package org.kernely.security;

import java.util.Hashtable;

import org.apache.shiro.web.servlet.IniShiroFilter;
import org.kernely.web.ContextServiceInterface;
import org.ops4j.pax.web.service.WebContainer;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.event.EventAdmin;

/**
 * Bundle's activator
 */
public class Activator implements BundleActivator {

	/**
	 * Called when the bundle is STARTING
	 */
	public final void start(BundleContext pBundleContext) throws Exception {

		// Get Pax Web http service
		ServiceReference refContainer = pBundleContext.getServiceReference("org.ops4j.pax.web.service.WebContainer");
		WebContainer http = (WebContainer) pBundleContext.getService(refContainer);
		ServiceReference refContext = pBundleContext.getServiceReference(ContextServiceInterface.class.getName());
		ContextServiceInterface contextService = (ContextServiceInterface) pBundleContext.getService(refContext);

		// Initialise Filter init config property
		Hashtable<String, String> props = new Hashtable<String, String>();
		String[] urls = { "/*" };
		http.registerFilter(new IniShiroFilter(), urls, new String[] {}, props, contextService.getContext());


	}

	/**
	 * Called when the Bundle is STOPPING
	 */
	public final void stop(BundleContext context) throws Exception {
	

	}
	
	

}
